local highlight = require("sknvim.util").highlight

local M = {}

M.colors = {
    black   = "#141414",
    red     = "#df715a",
    green   = "#729c67",
    yellow  = "#ae903b",
    blue    = "#5d94dc",
    magenta = "#c17ca2",
    cyan    = "#1faba5",
    grey    = "#a3a3a1",

    bright_black   = "#464645",
    bright_red     = "#ff8c6e",
    bright_green   = "#8dc47f",
    bright_yellow  = "#dbb545",
    bright_blue    = "#6fbaff",
    bright_magenta = "#f49acc",
    bright_cyan    = "#00d9d1",
    white          = "#e2e1de"
}

M.lualine_colors = {
    normal = {
        a = {bg = M.colors.grey,         fg = M.colors.black,    gui = 'bold'},
        b = {bg = M.colors.bright_black, fg = M.colors.white},
        c = {bg = "#202020",             fg = M.colors.white}
    },
    insert   = { a = {bg = M.colors.blue,   fg = M.colors.black, gui = 'bold'} },
    visual   = { a = {bg = M.colors.yellow, fg = M.colors.black, gui = 'bold'} },
    replace  = { a = {bg = M.colors.red,    fg = M.colors.black, gui = 'bold'} },
    command  = { a = {bg = M.colors.green,  fg = M.colors.black, gui = 'bold'} },
    inactive = { a = {bg = M.colors.grey,   fg = M.colors.black,  gui = 'bold'} }
}

function M:set_terminal_color()
    vim.g.terminal_ansi_colors = {
        self.colors.black,
        self.colors.red,
        self.colors.green,
        self.colors.yellow,
        self.colors.blue,
        self.colors.magenta,
        self.colors.cyan,
        self.colors.grey,

        self.colors.bright_black,
        self.colors.bright_red,
        self.colors.bright_green,
        self.colors.bright_yellow,
        self.colors.bright_blue,
        self.colors.bright_magenta,
        self.colors.bright_cyan,
        self.colors.white
    }

    vim.g.terminal_color_0 = self.colors.black
    vim.g.terminal_color_1 = self.colors.red
    vim.g.terminal_color_2 = self.colors.green
    vim.g.terminal_color_3 = self.colors.yellow
    vim.g.terminal_color_4 = self.colors.blue
    vim.g.terminal_color_5 = self.colors.magenta
    vim.g.terminal_color_6 = self.colors.cyan
    vim.g.terminal_color_7 = self.colors.grey

    vim.g.terminal_color_8 = self.colors.bright_black
    vim.g.terminal_color_9 = self.colors.bright_red
    vim.g.terminal_color_10 = self.colors.bright_green
    vim.g.terminal_color_11 = self.colors.bright_yellow
    vim.g.terminal_color_12 = self.colors.bright_blue
    vim.g.terminal_color_13 = self.colors.bright_magenta
    vim.g.terminal_color_14 = self.colors.bright_cyan
    vim.g.terminal_color_15 = self.colors.white
end

function M:set_highlight()
    highlight(
        {"Normal", "Terminal"},
        self.colors.white, self.colors.black,
        {"gui=NONE"}
    )
    highlight("EndOfBuffer", self.colors.black, "NONE", {})

    highlight(
        {"TabLine", "TabLineFill"},
        self.colors.white, "#202020",
        {"gui=NONE"}
    )

    highlight("ColorColumn",  "NONE",             "#202020",                {"gui=NONE"})
    highlight("StatusLine",   self.colors.grey,   "#202020",                {"gui=reverse"})

    highlight("CursorLine",   "NONE",             "#1b1b1b",                {"gui=NONE"})
    highlight("CursorLineNr", "NONE",             self.colors.black,        {"gui=NONE"})

    highlight("SignColumn",   self.colors.white,  self.colors.black,        {})
    highlight("LineNr",       "#484848", self.colors.black,        {})

    highlight("Visual",       "NONE",             "#282828",                {})
    highlight("Pmenu",        self.colors.white,  "#282828",                {})
    highlight("WinSeparator", "#323232",          "NONE",                   {"gui=NONE"})

    highlight("Search",       "NONE",             self.colors.bright_black, {"gui=bold"})
    highlight("CurSearch",    self.colors.black,  self.colors.grey,         {"gui=bold"})
end

function M:set_syntax_highlight()
    -- syntax highlight
    highlight(
        {"Define", "Include", "PreProc"},
        self.colors.bright_yellow, "NONE",
        {"gui=italic"}
    )

    highlight(
        {"Boolean", "Character", "Number", "Float"},
        self.colors.magenta, "NONE",
        {"gui=bold"}
    )

    highlight("Comment",     self.colors.grey,          "NONE", {"gui=italic"})
    highlight("Macro",       self.colors.yellow,        "NONE", {"gui=italic"})
    highlight("Title",       self.colors.bright_green,  "NONE", {"gui=italic,bold"})

    highlight("Underlined",  self.colors.cyan,          "NONE", {"gui=underline"})

    highlight("String",      self.colors.yellow,        "NONE", {"gui=bold"})

    highlight("Function",    self.colors.green,         "NONE", {"gui=bold"})
    highlight("Identifier",  self.colors.grey,          "NONE", {"gui=NONE"})
    highlight("Keyword",     self.colors.bright_yellow, "NONE", {"gui=NONE"})
    highlight("Type",        self.colors.cyan,          "NONE", {"gui=italic"})
    highlight("Structure",   self.colors.cyan,          "NONE", {"gui=italic,bold"})
    highlight("Typedef",     self.colors.cyan,          "NONE", {"gui=bold"})
    highlight("Conditional", self.colors.red,           "NONE", {"gui=bold"})
    highlight("Exception",   self.colors.red,           "NONE", {"gui=NONE"})
    highlight("Repeat",      self.colors.red,           "NONE", {"gui=NONE"})

    highlight("Operator",    self.colors.yellow,        "NONE", {"gui=NONE"})
    highlight("Statement",   self.colors.bright_yellow, "NONE", {"gui=bold"})
    highlight("Special",     self.colors.cyan,          "NONE", {"gui=bold"})
    highlight("SpecialChar", self.colors.red,           "NONE", {"gui=NONE"})
    highlight("Delimiter",   self.colors.bright_yellow, "NONE", {"gui=bold"})
    highlight("Constant",    self.colors.magenta,       "NONE", {"gui=italic"})
end

function M:set_indentblankline_highlight()
    highlight("IblIndent", "#303030", "NONE", {})
    highlight("IblScope",  "#606060", "NONE", {})
end

function M:set_gitsigns_highlight()
    highlight("GitSignsAdd",      self.colors.bright_green,  "NONE",            {"gui=bold"})
    highlight("GitSignsAddLn",     self.colors.blue,          "NONE",            {"gui=bold"})
    highlight("GitSignsChange",  self.colors.grey,          "NONE",            {"gui=bold"})
    highlight("GitSignsDelete",    self.colors.red,           "NONE",            {"gui=bold"})
    highlight("GitSignsDeleteLn",    self.colors.red,           "NONE",            {"gui=bold"})
end

function M:set_neotree_highlight()
    highlight("NeoTreeNormal",        self.colors.white,         self.colors.black, {})
    highlight("NeoTreeModified",      self.colors.yellow,        self.colors.black, {})

    highlight("NeoTreeIndentMarker",  self.colors.grey,          "NONE",            {})

    highlight("NeoTreeDirectoryName", self.colors.green,         "NONE",            {"gui=bold"})

    highlight("NeoTreeGitAdded",      self.colors.bright_green,  "NONE",            {"gui=bold"})
    highlight("NeoTreeGitStaged",     self.colors.blue,          "NONE",            {"gui=bold"})
    highlight("NeoTreeGitDeleted",    self.colors.red,           "NONE",            {"gui=bold"})
    highlight("NeoTreeGitIgnored",    "#484848",                 "NONE",            {"gui=bold"})
    highlight("NeoTreeGitRenamed",    self.colors.yellow,        "NONE",            {"gui=bold"})
    highlight("NeoTreeGitConflict",   self.colors.bright_red,    "NONE",            {"gui=bold"})
    highlight("NeoTreeGitModified",   self.colors.magenta,       "NONE",            {"gui=bold"})
    highlight("NeoTreeGitUnstaged",   self.colors.grey,          "NONE",            {"gui=bold"})
    highlight("NeoTreeGitUntracked",  self.colors.grey,          "NONE",            {"gui=bold"})

    highlight(
        {"NeoTreeFileIcon", "NeoTreeDirectoryIcon"},
        self.colors.yellow, "NONE",
        {"gui=bold"}
    )
end

return M
